package com.frost.controller;

import com.frost.exception.MyException;
import com.frost.service.UserSerivce;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by xulianquan on 2017/7/2.
 */
@Controller
@EnableAutoConfiguration
public class SampleController {
    public String name;
    @Autowired
    UserSerivce userSerivce;
    @RequestMapping("/")
    @ResponseBody
    public String greet() {
        return "Greetings from srping boot!";
    }

    @RequestMapping("/hello1")  //使用thymeleaf 模板
    public String index1(ModelMap map) {
        map.addAttribute("host", "http://blog.didispace.com");
        return "index";
    }

    @RequestMapping("/hello2")  //使用freemarker模板
    public String index2(ModelMap map) {
        map.addAttribute("host", "http://blog.didispace.com");
        return "index";
    }


    @RequestMapping("/jsonexceptest")
    public String jsonExcep() throws MyException {
        throw new MyException("test");
    }
    @RequestMapping("/commonexcep")
    public String commonExcep() throws Exception {
        throw new Exception("test");
    }
}
